import { userStore } from '@/store/user';

/**
 * 判断是否有权限。根据传入的权限标识，查看是否存在于用户的权限标识集合内。
 */
export const hasPermission = (requirePerm: string) => {
  const currentPerm = userStore().user.permissions;
  for (let i = 0; i < currentPerm.length; i++) {
    if (requirePerm.includes(currentPerm[i])) {
      return true;
    }
  }
  return false;
};

export const hasPermissions = (requirePerm: string[]) => {
  const currentPerm = userStore().user.permissions;
  for (let i = 0; i < requirePerm.length; i++) {
    for (let ii = 0; ii < currentPerm.length; ii++) {
      if (requirePerm[i].includes(currentPerm[ii])) {
        return true;
      }
    }
  }
  return false;
};
